import 'package:exsun_plate_app/widget/home/map/home_map_page.dart';
import 'package:flutter/material.dart';
import 'package:exsun_plate_app/common/constant.dart';

class HomePage extends StatefulWidget {
  @override
  HomePageState createState() => new HomePageState();
}

class HomePageState extends State<HomePage> {
  int _curIndex = 0;
  PageController _pageController = new PageController();

  _onPageChanged(int index) {
    setState(() {
      _curIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: PreferredSize(
          child: new AppBar(
            title: new Text('首页'),
            backgroundColor: Colors.transparent,
            elevation: 0,
            brightness: Brightness.light,
          ),
          preferredSize: Size.zero),
      body: PageView.builder(
        onPageChanged: _onPageChanged,
        controller: _pageController,
        itemBuilder: (BuildContext context, int index) {
          if (index == 0) {
            return HomeMap();
          } else if (index == 1) {
            return new Text("我是第二页");
          } else {
            return new Text("我是第三页");
          }
        },
        itemCount: 3,
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _curIndex,
        items: [
          BottomNavigationBarItem(
            icon: _curIndex == 0
                ? (new Image.asset('images/menubar_monitoring_icon_s.png'))
                : (new Image.asset('images/menubar_monitoring_icon_n.png')),
            title: Center(child: new Text("地图监控")),
          ),
          BottomNavigationBarItem(
              icon: _curIndex == 1
                  ? (new Image.asset('images/menubar_statistics_icon_s.png'))
                  : new Image.asset('images/menubar_statistics_icon_n.png'),
              title: new Text("统计")),
          BottomNavigationBarItem(
              icon: _curIndex == 2
                  ? (new Image.asset(
                      'images/menubar_personalcenter_icon_s.png'))
                  : new Image.asset('images/menubar_personalcenter_icon_n.png'),
              title: new Text("我的")),
        ],
        onTap: (index) {
          _pageController.animateToPage(index,
              duration: const Duration(milliseconds: 300), curve: Curves.ease);
        },
        selectedFontSize: 12,
        unselectedFontSize: 12,
        fixedColor: Constants.mainGreenColor,
        type: BottomNavigationBarType.fixed,
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(HomePage oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}
